package demo.practice.uf;

public class P547 {

    public int findCircleNum(int[][] isConnected) {

        if (isConnected == null || isConnected.length == 0 || isConnected[0].length == 0)
            return 0;

        UFRankUnion uf = new UFRankUnion(isConnected.length);

        for (int i = 0; i < isConnected.length; i++) {
            for (int j = i + 1; j < isConnected.length; ++j) {
                if(isConnected[i][j]==1)
                    uf.join(i,j);
            }
        }

        return uf.plant;
    }


}
